package com.example.leetdemo.finash;

public class Solution2683 {

    public boolean doesValidArrayExist(int[] derived) {

        int[][] origin = new int[2][derived.length];
        origin[0][0] = 0;
        origin[1][0] = 1;

        for (int i = 0; i < derived.length - 1; i++) {
            if (derived[i] == 0) {
                origin[0][i + 1] = origin[0][i];
                origin[1][i + 1] = origin[1][i];
            } else {
                origin[0][i + 1] = 1 ^ origin[0][i];
                origin[1][i + 1] = 1 ^ origin[1][i];
            }
        }
        return (origin[0][0] ^ origin[0][derived.length - 1]) == derived[derived.length - 1]
                || (origin[1][0] ^ origin[1][derived.length - 1]) == derived[derived.length - 1];
    }

    public static void main(String[] args) {
        System.err.println(1 ^ 1);
        System.err.println(0 ^ 1);
    }

}
